home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Inside Mac Games Volume 4 #4
/
IMG 36 April 1996.iso
/
Essentials
/
MGD 4⁄96ƒ
/
MGW1Codeƒ
/
MGWGraphicsBWLite.c
< prev
next >
Wrap
Text File
|
1995-06-25
|
5KB
|
128 lines
//==============================================================================================\\
// ------------------------------------------------------------------------------- \\
// MGWGraphicsBWLite1.h version 1.0.0 copyright © 1993…1995 Jamie McCornack, john calhoun \\
// ------------------------------------------------------------------------------- \\
// Constants and prototypes for Macintosh GameWriter 1.0.0, a training program… \\
// …for beginning Mac game programmers. MGW1 includes MGWUtilities1.c, MGWSound1.c,… \\
// …MGWGraphics1.c, MGWGraphicsBWLite1.c, HelloWorld.rsrc and an assortment of demo… \\
// programs; projects HelloWorld1.π etc. and source code files HelloWorld1.c etc. \\
// A tutorial is available in Tricks of the Mac Game Programming Gurus, published… \\
// …by Hayden Books \\
// \\
// This code is offered by the copyright holders for no fee and for whatever use… \\
// …you care to make of it, but we do hope you remember where it came from. \\
// \\
// Please send bug reports to MacGameDev at America OnLine. macgamedev@aol.com \\
// Suggestions and observations are also appreciated. \\
// Updates and upgrades will be available now and then from the above e-mail address. \\
//==============================================================================================\\
// These functions have no error checking and are dangerous. For instruction only.
// DON'T USE THIS FOR REAL PROGRAMS! Use MGWGraphics1.c instead,…
// …which will require MGWUtilities.c in the program.
#include "MGWExterns1.h"
//============================================================== Functions
//-------------------------------------------------------------- CreateOffScreenBitMapLite
// Creates an offscreen bitmap, without any error checking.
// If this function fails to create the bitmap, the program crashes.
// DO NOT USE THIS FUNCTION in any real program.
void CreateOffScreenBitMapLite (Rect *theRect, GrafPtr *offScreen)
{
GrafPtr theBWPort;
BitMap theBitMap;
long theRowBytes;
theBWPort = (GrafPtr)(NewPtr(sizeof(GrafPort)));
OpenPort(theBWPort);
theRowBytes = (long)((theRect->right - theRect->left + 15L) / 16L) * 2L;
theBitMap.rowBytes = (short)theRowBytes;
theBitMap.baseAddr = NewPtr((long)theBitMap.rowBytes *
(theRect->bottom - theRect->top));
// ERROR CHECKING GOES HERE IN CreateOffScreenBitMap()--see MGWGraphics1.c
theBitMap.bounds = *theRect;
// ERROR CHECKING GOES HERE IN CreateOffScreenBitMap()--see MGWGraphics1.c
SetPortBits(&theBitMap);
ClipRect(theRect);
RectRgn(theBWPort->visRgn, theRect);
EraseRect(theRect);
*offScreen = theBWPort;
}
//-------------------------------------------------------------- KillOffScreenBitMap
// Disposes of an offscreen bitmap, and frees the memory for other purposes.
void KillOffscreenBitMap (GrafPtr *wasPort)
{
if (wasPort != nil)
{
ClosePort(*wasPort);
*wasPort = nil;
}
}
//-------------------------------------------------------------- LoadGraphicLite
// Handy function that loads a PICT graphic, get's its bounds and draws it.
// The port drawn to is assumed the current port. No scaling is done.
void LoadGraphicLite (short thePictID)
{
Rect bounds;
PicHandle thePicture;
thePicture = GetPicture(thePictID); // Load graphic from resource fork.
// ERROR CHECKING GOES HERE IN LoadGraphic()--see MGWGraphics1.c
HLock((Handle)thePicture); // If we made it this far, lock handle.
bounds = (*thePicture)->picFrame; // Get a copy of the picture's bounds.
HUnlock((Handle)thePicture); // We can unlock the picture now.
OffsetRect(&bounds, -bounds.left, -bounds.top); // Offset bounds rect to (0, 0).
DrawPicture(thePicture, &bounds); // Draw picture to current port.
ReleaseResource((Handle)thePicture); // Dispose of picture from heap.
}
//-------------------------------------------------------------- InitToolbox
// This routine doesn't belong in a Graphics file.
// It is here in MGWGraphicsBWLitebecause it needs…
// to go somewhere, and I'm trying to keep HelloWorld1.π short and sweet.
// For the rest of the HelloWorld projects, you'll find this routine in MGWUtilities.c.
// void InitToolbox (void);
//
// The calls herein MUST be called before you do anything else.
// Otherwise, you'll get all sorts of System Errors.
void InitToolbox (void)
{
InitGraf(&qd.thePort); // Initialize QuickDraw variables for our program.
InitFonts(); // Initialize fonts.
FlushEvents(everyEvent, 0); // Clear event queue of any pending events.
InitWindows(); // Initialize the Window Manager.
InitMenus(); // Ditto for the Menu Manager.
TEInit(); // blah, blah Text Edit.
InitDialogs(0L); // blah, blah Dialog Manager.
InitCursor(); // Set the cursor to the arrow cursor and init.
MaxApplZone(); // Grab application memory.
MoreMasters(); // Allocate a block of master pointers.
MoreMasters(); // And allocate more.
MoreMasters(); // And more.
MoreMasters(); // Hey, lets do it again too.
GetDateTime((unsigned long *)&qd.randSeed); // Randomize random seed.
}
//------------------------------------------------------------------------------------------\\
// End MGWGraphicsBWLite.c \\
//------------------------------------------------------------------------------------------\\